#pragma once

#include "Board.h"
#include "Move.h"
#include <vector>

class MoveGenerator
{
private:
	bool _blackAttackBoard[NUM_SQUARES];
	bool _whiteAttackBoard[NUM_SQUARES];

	byte _blackKingPosition = 0,
		 _whiteKingPosition = 0;

	bool _blackCheck = false,
		 _whiteCheck = false,
		 _blackMate = false,
		 _whiteMate = false;
	bool _generateMoves = true;

public:
	MoveGenerator();

	void Generate(Board &b, Move *lastMove, std::vector<Move> &moves);

private:
	void Generate(Board &b, Move *lastMove, std::vector<Move> &moves, bool checkForMate);

	inline void GeneratePawnMoves(Board &b, byte idx, std::vector<Move> &moves);
	inline void GenerateRookMoves(Board &b, byte idx, std::vector<Move> &moves);
	inline void GenerateKnightMoves(Board &b, byte idx, std::vector<Move> &moves);
	inline void GenerateBishopMoves(Board &b, byte idx, std::vector<Move> &moves);
	inline void GenerateQueenMoves(Board &b, byte idx, std::vector<Move> &moves);
	inline void GenerateKingMoves(Board &b, byte idx, std::vector<Move> &moves);
	inline void GenerateCastleMoves(Board &b, PieceColor color, std::vector<Move> &moves);
	inline void SearchForMate(Board &b, std::vector<Move> &moves);

	inline bool AnalyzeMove(Board &b, byte srcPos, byte dstPos, std::vector<Move> &moves, uint flags = NONE);

	inline void UpdateFlags(uint &flags);

	void ClearAttackBoard();
};